package com.dems.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dems.util.VerifyCode;

/**
 * Servlet implementation class ValiImageServlet
 */
@WebServlet("/ValiImageServlet")
public class ValiImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ValiImageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//控制缓存，防止浏览器使用验证码图片的缓存
		response.setDateHeader("Expires", -1);
		response.setHeader("Cache-control", "no-cache");
		//调用工具类产生一个验证码的图片
		VerifyCode vc = new VerifyCode();
		vc.drawImage(response.getOutputStream());
		//获取验证码的纯文本内容
		String code = vc.getCode();
		HttpSession session = request.getSession();
		session.setAttribute("code", code);
		System.out.println(code);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
